//
//  StoreViewController.m
//  AnXin100
//
//  Created by Sakura on 2018/11/10.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "StoreViewController.h"
#import "AXMyWdzjTableViewCell.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
@interface StoreViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *mainTable;

@property (nonatomic, strong) UIView *tableHeaderView;
/** 假图片数据 */
@property (nonatomic, strong) NSArray<NSString *> *imageNames;
@property (nonatomic, strong) NSArray<NSString *> *titleNames;
@property (nonatomic, strong) NSArray<NSString *> *priceNames;
@end

@implementation StoreViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.titleNames = @[@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发1",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发2",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发3",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发4",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发5",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发6",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发7",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发8",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发9",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发10"];
    self.imageNames = @[@"j1.jpg",@"j2.jpg",@"j3.jpg",@"j4.jpg",@"j5.jpg",@"j6.jpg",@"j7.jpg",@"j8.jpg",@"j9.jpg",@"j10.jpg"];
    self.priceNames =@[@"¥90",@"¥91",@"¥92",@"¥93",@"¥94",@"¥95",@"¥96",@"¥97",@"¥98",@"¥99"];
    [self.view addSubview:self.mainTable];
    _mainTable.tableHeaderView = self.tableHeaderView;
    
}

- (UITableView *)mainTable {
    if (!_mainTable) {
        _mainTable = [[UITableView alloc] initWithFrame:CGRectMake(0, Hn, SCREEN_WIDTH, SCREEN_HEIGHT - Hn) style:UITableViewStylePlain];
        _mainTable.delegate = self;
        _mainTable.dataSource = self;
        [_mainTable registerClass:[AXMyWdzjTableViewCell class] forCellReuseIdentifier:@"AXMyWdzjTableViewCell"];
    }
    return _mainTable;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _titleNames.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
     return [tableView cellHeightForIndexPath:indexPath model:nil keyPath:@"model" cellClass:[AXMyWdzjTableViewCell class] contentViewWidth:SCREEN_WIDTH];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AXMyWdzjTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AXMyWdzjTableViewCell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.productImageView.image = [UIImage imageNamed:self.imageNames[indexPath.row]];
    cell.nameLabel.text = self.titleNames[indexPath.row];
    cell.priceLabel.text = self.priceNames[indexPath.row];
    return cell;
}


- (UIView *)tableHeaderView {
    if (!_tableHeaderView) {
        _tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
        UIImageView *headImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 55, 55)];
        headImage.image = [UIImage imageNamed:@"xy.jpg"];
        headImage.layer.cornerRadius = 22.5;
        [_tableHeaderView addSubview:headImage];
        
        UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxY(headImage.frame) + 10, 10,  200, 27.5)];
        nameLabel.text = @"多啦A梦店铺";
        nameLabel.textColor = [UIColor colorWithHex:0x333333];
        nameLabel.font = FONT_FOURTEEN;
        [_tableHeaderView addSubview:nameLabel];
        
        UILabel *alertLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxY(headImage.frame) + 10, 37.5,  200, 27.5)];
        alertLabel.text = @"公告：欢度台湾解放，喜迎林志玲回归";
        alertLabel.textColor = [UIColor colorWithHex:0x333333];
        alertLabel.font = FONT_TWELVE;
        [_tableHeaderView addSubview:alertLabel];
        
        UIImageView *storeImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headImage.frame) + 40, SCREEN_WIDTH, 115)];
        storeImage.image = [UIImage imageNamed:@"ptsfx.jpg"];
        [_tableHeaderView addSubview:storeImage];
        
        UIButton *attentionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        attentionBtn.frame = CGRectMake(SCREEN_WIDTH - 64, 0, 54, 22);
        attentionBtn.backgroundColor = COLOR_ORG;
        attentionBtn.titleLabel.font = FONT_TWELVE;
        attentionBtn.centerY_sd = alertLabel.centerY_sd;
        [attentionBtn setTitle:@"关注" forState:UIControlStateNormal];
        [attentionBtn setImage:[UIImage imageNamed:@"attention"] forState:UIControlStateNormal];
        attentionBtn .imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        [_tableHeaderView addSubview:attentionBtn];
        
        NSArray *titleAry = @[@"推荐",@"价格",@"销量",@"筛选"];
        CGFloat y = 0;
        for (NSInteger i = 0; i < titleAry.count; i++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(SCREEN_WIDTH / 4 * i, CGRectGetMaxY(storeImage.frame) + 30, SCREEN_WIDTH / 4, 30);
            [btn setTitle:titleAry[i] forState:UIControlStateNormal];
            [btn setTitleColor:COLOR_Gray forState:UIControlStateNormal];
            [btn setTitleColor:COLOR_GREEN forState:UIControlStateSelected];
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
            btn.tag = 100 + i;
            if (i == 0) {
                btn.selected = YES;
            }
            [_tableHeaderView addSubview:btn];
            [btn addTarget:self action:@selector(clickAciton:) forControlEvents:UIControlEventTouchUpInside];
            y = CGRectGetMaxY(btn.frame);
        }
        _tableHeaderView.mj_h = y + 10;
    }
    return _tableHeaderView;
}

@end
